﻿using System;
using System.Collections.Generic;
using System.Text;
using BCMS.Business.DataContract;
using System.ComponentModel;
using System.Collections;

namespace BCMS.FrontEnd.DataContract
{
    public class ReleaseUI : INotifyPropertyChanged, IComparer
    {
        public int ReleaseId { set; get; }
        public DateTime StartDate { set; get; }
        public DateTime ExpireDate { set; get; }
        public long Qtty { set; get; }
        public decimal ParValue { set; get; }
        public decimal TotalValue { set; get; }
        private string _name;
        public string Name
        {
            get { return _name; }
            set
            {
                if (_name != value)
                {
                    _name = value;
                    this.NotifyPropertyChanged("Name");
                }
            }
        }        
        private string _rCode;
        public string RCode
        {
            get { return _rCode; }
            set
            {
                if (_rCode != value)
                {
                    _rCode = value;
                    this.NotifyPropertyChanged("RCode");
                }
            }
        }
        private long _rLow;
        public long RLow
        {
            get { return _rLow; }
            set
            {
                if (_rLow != value)
                {
                    _rLow = value;
                    this.NotifyPropertyChanged("RLow");
                }
            }
        }
        private long _rHigh;
        public long RHigh
        {
            get { return _rHigh; }
            set
            {
                if (_rHigh != value)
                {
                    _rHigh = value;
                    this.NotifyPropertyChanged("RHigh");
                }
            }
        }
        private string _target;
        public string Target
        {
            get { return _target; }
            set
            {
                if (_target != value)
                {
                    _target = value;
                    this.NotifyPropertyChanged("Target");
                }
            }
        }
        private string _detail;
        public string Detail
        {
            get { return _detail; }
            set
            {
                if (_detail != value)
                {
                    _detail = value;
                    this.NotifyPropertyChanged("Detail");
                }
            }
        }
        private string _note;
        public string Note
        {
            get { return _note; }
            set
            {
                if (_note != value)
                {
                    _note = value;
                    this.NotifyPropertyChanged("Note");
                }
            }
        }
        private string _kind;
        public string Kind
        {
            get { return _kind; }
            set
            {
                if (_kind != value)
                {
                    _kind = value;
                    this.NotifyPropertyChanged("Kind");
                }
            }
        }
        private string _status;
        public string Status
        {
            get { return _status; }
            set
            {
                if (_status != value)
                {
                    _status = value;
                    this.NotifyPropertyChanged("Status");
                }
            }
        }

        public ReleaseUI() { }

        public ReleaseUI(ReleaseInfo item)
        {
            this.ReleaseId = item.ReleaseId;
            this.RCode = item.Name;
            this.StartDate = item.StartDate;
            this.ExpireDate = item.ExpireDate;
            this.Qtty = item.Qtty;
            this.ParValue = item.ParValue;
            this.RCode = item.RCode;
            this.RLow = item.RLow;
            this.RHigh = item.RHigh;
            switch (item.Target)
            {
                case (int)RTarget.CUSTOMER:
                    this.Target = "Khách hàng";
                    break;
                case (int)RTarget.PARTNER:
                    this.Target = "Đối tác";
                    break;
                case (int)RTarget.STAFF:
                    this.Target = "Nhân viên";
                    break;
                case (int)RTarget.OTHER:
                    this.Target = "Khác";
                    break;
                default:
                    this.Target = "UNKNOWN";
                    break;
            }
            this.TotalValue = item.Qtty * item.ParValue;
            this.Detail = item.Detail;
            this.Note = item.Note;
            this.ReleaseId = item.ReleaseId;
            switch (item.Kind)
            {
                case (int)RKind.SELL:
                    this.Kind = "Bán";
                    break;
                case (int)RKind.DISCOUNT:
                    this.Kind = "Chiết khấu";
                    break;
                case (int)RKind.GIFT:
                    this.Kind = "Quà tặng";
                    break;
                case (int)RKind.OTHER:
                    this.Kind = "Khác";
                    break;
                default:
                    this.Kind = "UNKNOWN";
                    break;
            }
            switch (item.Status)
            {
                case (int)RStatus.NORMAL:
                    this.Status = string.Empty;
                    break;
                case (int)RStatus.DISPOSED:
                    this.Status = "Đã hủy";
                    break;
                case (int)RStatus.DELETED:
                    this.Status = "Đã xóa";
                    break;
                default:
                    this.Status = "UNKNOWN";
                    break;
            }
        }

        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;
        private void NotifyPropertyChanged(string name)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(name));
        }

        #endregion

        #region IComparer Members

        public int Compare(object x, object y)
        {
            return ((ReleaseUI)x).ReleaseId.CompareTo(((ReleaseUI)y).ReleaseId);
        }

        #endregion
    }

    public enum RTarget
    {
        CUSTOMER = 1,
        PARTNER = 2,
        STAFF = 3,
        OTHER = 4
    }

    public enum RKind
    {
        SELL = 1,
        DISCOUNT = 2,
        GIFT = 3,
        OTHER = 4
    }

    public enum RStatus
    {
        NORMAL = 1,
        DISPOSED = 2,
        DELETED = 3
    }
}
